package com.fuchen.shengwu.service.report.controller;

import com.fuchen.shengwu.entity.DatasourceConnectionEntity;
import com.fuchen.shengwu.repository.DatasourceConnectionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by luganlin on 12/05/2018.
 */
@RestController
public class ConnectionController {

    @Autowired
    DatasourceConnectionRepository datasourceRepository;

    @RequestMapping(value = "/connections/{id}", method = RequestMethod.GET)
    public DatasourceConnectionEntity getConnection(@PathVariable(name = "id") Long id) {
        return datasourceRepository.findOneById(id);
    }

    @RequestMapping(value = "/connections/{id}/tables", method = RequestMethod.GET)
    public List<String> getTablesByConnection(@PathVariable(name = "id") Long id) {
        DatasourceConnectionEntity oneConnection =  datasourceRepository.findOneById(id);
        return null;
        //return datasourceRepository.findOneById(id);
    }


    @RequestMapping(value = "/connections/", method = RequestMethod.GET)
    public List<DatasourceConnectionEntity> getConnections() {
        return datasourceRepository.findAll();
    }

    @RequestMapping(value = "/connections/", method = RequestMethod.POST)
    public void createConnection(@RequestBody DatasourceConnectionEntity datasourceConnectionEntity) {
        datasourceRepository.save(datasourceConnectionEntity);
    }


}
